package com.ling.minio.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import io.minio.MinioClient;

@Configuration
public class MinioConfig {

    @Value("${minio.endpoint}")
    private String endpoint;

    @Value("${minio.access-key}")
    private String accessKey;

    @Value("${minio.access-secret}")
    private String secretKey;

    @Bean
    public MinioClient minioClient(){
        try {
            MinioClient.Builder builder = MinioClient.builder();
            builder.endpoint(endpoint);
            if (StringUtils.hasLength(accessKey) && StringUtils.hasLength(secretKey)) {
                builder.credentials(accessKey,secretKey);
            }
            return builder.build();
        } catch (Exception e) {
            return null;
        }
    }
}